const routerURL  = 'https://newapi.shanqueyi.com/';//接口地址
export const imgNetUrl = 'https://newapi.shanqueyi.com';//接口中图片地址  旧：https://tea.lanlitao.net
export const baseUrl = 'https://newapi.shanqueyi.com/Public/webpic/shanQueYiCImg/';//项目中图片https地址
// export const baseUrl = 'http://admin.shanqueyi.com/shanQueYiCImg/';//A端ftp
export function uniRequest (url, method, data) {
	return new Promise ((resolve, reject) => {
		uni.request({
			url: routerURL + url,
			method: method || 'GET',
			data: data || {},
			header: (method == 'POST' ?
						{ 'Content-Type': 'application/x-www-form-urlencoded;charset=utf-8' } :
						{ 'Content-Type': 'application/json;charset=utf-8' }),
			success: res => {
				// console.log('url', url)
				if(res.data.code == "000000") {
					resolve(res.data);
				}else{
					if(url == 'isMsgRead' || url == 'memberOpenDoor') {
						resolve(res.data);
					}else {
						if(res.data.code == "900001" && res.data.message == '系统检测到您未登录') {
							uni.removeStorageSync('token');
							uni.removeStorageSync('userInfo');
							uni.navigateTo({ url: '/pages/personalCenter/login?type=2' })
						}else {
							uni.showToast({
								title: res.data.message, icon: 'none', duration: 3000
							});
						}
					}
				}
			},
			fail: err => {
				reject(err);
				uni.showToast({
					title: err.data.message, icon: 'none', duration: 3000
				});
			}
		});
	});
};